package com.dlc.shop.systemtest.api.amount;

import com.dlc.shop.bean.app.vo.ProductVO;
import com.dlc.shop.bean.model.OfflineHandleEvent;
import com.dlc.shop.bean.model.Product;
import com.dlc.shop.bean.param.ProductParam;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;

import java.util.Objects;

/**
 * @author lanhai
 * 商品数据，为啥叫商品数据不叫商品测试呢，因为这个商品在订单里面都会用到
 */
public class ProductApi {


    /**
     * 创建商品
     * @param productParam
     * @return
     * double price,double deliveryAmount,Integer mold
     */
    public static Long createProduct(ProductParam productParam) {
        String url = Constant.SHOP_URL + "/prod/prod";
        boolean useMainShop = Objects.equals(productParam.getShopId(),1L);
        return HttpUtil.post(url, productParam, Long.class,useMainShop);
    }

    public static Long save(ProductParam productParam){
        String url = Constant.SHOP_URL + "/prod/prod";
        return HttpUtil.post(url,productParam,Long.class);
    }
    /**
     *获取商品详情
     */
    public static Product getProductInfo(Long id){
        String url = Constant.SHOP_URL + "/prod/prod/info/"+id;
        return HttpUtil.get(url,Product.class);
    }

    /**
     * 删除商品
     */
    public static void  delete(Long prodId){
        String url = Constant.SHOP_URL+"/prod/prod/"+prodId;
        HttpUtil.delete(url);
    }

    /**
     * 用户获取商品详情
     */
    public static ProductVO getProdInfo(Long productId) {
        String url = Constant.API_URL + "/prod/prodInfo?prodId=" + productId;
        return HttpUtil.get(url, ProductVO.class);
    }

    /**
     * 平台审核商品
     */
    public static void audit(OfflineHandleEvent offlineHandleEvent) {
        String url = Constant.PLATFORM_URL + "/prod/prod/auditProd";
        HttpUtil.post(url, offlineHandleEvent);
    }

}
